import { swagger } from '@app/constants/swagger';
import { INestApplication } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

export const setupSwagger = (app: INestApplication, config: ConfigService) => {
  const options = new DocumentBuilder().setTitle(config.get<string>(swagger.title, swagger.title)).setDescription(config.get(swagger.description, swagger.description)).addBearerAuth().build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup(config.get(swagger.path, ''), app, document, {
    swaggerOptions: {
      useGlobalPrefix: true,
    },
  });
};
